import React, { useRef, useState } from 'react';
import { connect } from 'umi';
import TableDataBlock from '@/components/TableDataBlock';
import PopImgShow from '@/components/PopImgShow';
import RoleSetForm from './components/Form';
import Detail from './components/details';
const PlanList = (props) => {
  const { loading, dispatch, list } = props;
  const childRef = useRef();
  const [visible, setVisible] = useState(false);
  const [visible1, setVisible1] = useState(false);
  // 搜索参数

  const getColumns = [
    {
      title: '自提点名称',
      dataIndex: 'codeName',
    },
   
    {
      title: '省份',
      dataIndex: 'scamAmount',
    },
    {
      title: '城市',
      dataIndex: 'chatUserAmount',
    },
    {
      title: '地区',
      dataIndex: 'addUserAmount',
    },
    {
      title: '地址',
      dataIndex: 'quitUserAmount',
    },
    {
      title: '联系电话',
      dataIndex: 'organizationAdminName',
    },
    {
      type: 'handle',
      width: 200,
      dataIndex: 'id',
      render: (val, record) => [

        {
          auth: true,
          type: 'edit',
          click: () => {
            dispatch({
              type: 'system/fetchChatCodeDetail',
              payload: {
                chatCodeId: val,
              },
              callback: (e) => {
                handleSaveRole(e);
              },
            });
          },
        },
      ],
    },
  ];
  const handleCallback = () => {
    childRef.current.fetchGetData();
  };
  const handleSaveRole = (detail = {}) => {
    setVisible(() => {
      return {
        show: true,
        detail,
      };
    });
  };
  const extraBtn = [
    {
      text: '新增自提点',
      onClick: () => {
        handleSaveRole();
      },
    },
  ];

  return (
    <>
      <TableDataBlock
        btnExtra={extraBtn}
        cRef={childRef}
        loading={loading}
        columns={getColumns}
        rowKey={(record) => `${record.id}`}
        dispatchType="system/fetchListChatCode"
        {...list}
      ></TableDataBlock>
      <RoleSetForm
        childRef={childRef}
        visible={visible}
        onClose={() => setVisible(false)}
        handleCallback={handleCallback}
      ></RoleSetForm>
      <Detail
        visible={visible1}
        onClose={() => setVisible1(false)}
        handleCallback={handleCallback}
      ></Detail>
    </>
  );
};

export default connect(({ system, loading }) => ({
  list: system.chatCodeList,
  loading: loading.models.system,
}))(PlanList);
